import { useEffect, useState, type JSX } from "react";
import { getCurrentToken } from "../service/modules/login";
import { Navigate } from "react-router-dom";

function RouterAuth({ children }: { children: JSX.Element }) {
  const [isAuth, setIsAuth] = useState<boolean>(!!getCurrentToken());
  useEffect(() => {
    setIsAuth(!!getCurrentToken());
  }, []);
  return isAuth ? children : <Navigate to="/login" replace></Navigate>;
  // return children;
}
export default RouterAuth;
